from sqlalchemy.orm import Session
from typing import List, Optional
from app.models.user import UserCreate, UserUpdate, UserEntity
from app.repository.user_repository import UserRepository

class UserService:
    @staticmethod
    def create_user(db: Session, user_create: UserCreate) -> UserEntity:
        repository = UserRepository(db)
        return repository.create(user_create)

    @staticmethod
    def get_user(db: Session, user_id: int) -> Optional[UserEntity]:
        repository = UserRepository(db)
        return repository.get_by_id(user_id)

    @staticmethod
    def get_user_by_email(db: Session, email: str) -> Optional[UserEntity]:
        repository = UserRepository(db)
        return repository.get_by_email(email)

    @staticmethod
    def get_users(db: Session, skip: int = 0, limit: int = 100) -> List[UserEntity]:
        repository = UserRepository(db)
        return repository.get_list(skip=skip, limit=limit)

    @staticmethod
    def update_user(db: Session, user_id: int, user_update: UserUpdate) -> Optional[UserEntity]:
        repository = UserRepository(db)
        return repository.update(user_id, user_update)

    @staticmethod
    def delete_user(db: Session, user_id: int) -> bool:
        repository = UserRepository(db)
        return repository.delete(user_id)
        
    @staticmethod
    def get_max_row_index(db: Session) -> int:
        repository = UserRepository(db)
        return repository.get_max_row_index()
